<!DOCTYPE html>
<!--
  All Rights Reserved.

  @author jparent@google.com (Julie Parent)
--><html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.ui.editor.ToolbarFactory</title>
<script src="../../base.js"></script>
<script>
  goog.require('goog.testing.ExpectedFailures');
  goog.require('goog.testing.editor.TestHelper');
  goog.require('goog.testing.jsunit');
  goog.require('goog.ui.editor.ToolbarFactory');
</script>
</head>
<body>
<div id="myField">foo</div>
<script>
var helper = new goog.testing.editor.TestHelper(goog.dom.getElement('myField'));
var expectedFailures = new goog.testing.ExpectedFailures();

function setUp() {
  helper.setUpEditableElement();
}

function tearDown() {
  helper.tearDownEditableElement();
  expectedFailures.handleTearDown();
}

/**
 * Makes sure we have the correct conversion table in
 * goog.ui.editor.ToolbarFactory.LEGACY_SIZE_TO_PX_MAP_. Can only be tested in
 * a browser that takes legacy size values as input to execCommand but returns
 * pixel size values from queryCommandValue. That's OK because that's the only
 * situation where this conversion table's precision is critical. (When it's
 * used to size the labels of the font size menu options it's ok if it's a few
 * pixels off.)
 */
function testGetLegacySizeFromPx() {
  // We will be warned if other browsers start behaving like webkit pre-534.7.
  expectedFailures.expectFailureFor(
      !goog.userAgent.WEBKIT ||
      (goog.userAgent.WEBKIT && goog.userAgent.isVersion('534.7')));
  try {
    var fieldElem = goog.dom.getElement('myField');
    // Start from 1 because size 0 is bogus (becomes 16px, legacy size 3).
    for (var i = 1; i <
        goog.ui.editor.ToolbarFactory.LEGACY_SIZE_TO_PX_MAP_.length; i++) {
      helper.select(fieldElem, 0, fieldElem, 1);
      document.execCommand('fontSize', false, i);
      helper.select('foo', 1);
      var value = document.queryCommandValue('fontSize');
      assertEquals('Px size ' + value + ' should convert to legacy size ' + i,
          i, goog.ui.editor.ToolbarFactory.getLegacySizeFromPx(
              parseInt(value, 10)));
    }
  } catch (e) {
    expectedFailures.handleException(e);
  }
}
</script>
</body>
</html>
  
